<?php
/**
 * ============================================================================
 * 版权所有 2008-2011 多多网络，并保留所有权利。
 * 网站地址: http://soft.duoduo123.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
*/
session_start();
error_reporting(0);
include('comm/config.php');
include_once 'comm/page.class.php';
include_once 'comm/checkpostandget.php';
include_once '../comm/msgset.php';

function json_to_array($web){
$arr=array();
foreach($web as $k=>$w){
if(is_object($w)) $arr[$k]=json_to_array($w);  //判断类型是不是object
else $arr[$k]=$w;
}
return $arr;
}

function directory_size($directory) {
      $directorySize=0;
/* Open the directory and read its contents. */
      if ($dh = @opendir($directory)) {
/* Iterate through each directory entry. */
         while (($filename = readdir ($dh))) {
/* Filter out some of the unwanted directory entries. */
            if ($filename != "." && $filename != "..")
            {
// File, so determine size and add to total.
               if (is_file($directory."/".$filename))
                  $directorySize += filesize($directory."/".$filename);
// New directory, so initiate recursion. */
                  if (is_dir($directory."/".$filename))
                     $directorySize += directory_size($directory."/".$filename);
            }
        } #endWHILE
     } #endIF
@closedir($dh);
     return $directorySize;
} #end directory_size()

function cacheSize(){
    echo round((directory_size($_GET['cache_dir']) / (1024*1024)), 2);
}

function checkLogin(){
	global $BIAOTOU;
	global $msg_zhuce;
	$name=trim($_POST['ddusername']);
	$pwd=trim($_POST['dduserpwd']);
	$md5pwd=md5($pwd);
	if(UC==1){
	    include 'data/config.inc.php';
		include 'uc_client/client.php';
		
		/////////////////////////////////////
	    $uc_name=iconv("utf-8","utf-8",$name);
		list ($uid, $uc_name, $pwd, $email) = uc_user_login($uc_name, $pwd);  
		/////////////////////////////////////
		
		if ($uid > 0) {
			$sql="SELECT Id,dengji FROM " . $BIAOTOU . "user WHERE ddusername='".$name."'";
			$query=mysql_query($sql);
			$dduser=mysql_fetch_array($query);
			$Id=$dduser['Id'];
			$dengji=$dengji['dengji'];
			if (!$Id) { //判断用户是否存在于用户表，不存在则加到多多的会员表中
				$sj = date("Y-m-d H:i:s");
				$insert = "INSERT INTO " . $BIAOTOU . "user(Id,ddusername,ddpassword,email,qq,regtime,lastlogintime,loginnum,tjr,pass_question,pass_answer,money,dengji) values ('$uid','$name','$pwd','$email','$qq','$sj','$sj',1,'$tjr','$question','$answer','" . ZHUCESONG . "','".ZHUCESONGLEVEL."')";
				mysql_query($insert);
				$tg = round(TGBL / FXBL * 100, 2);
				$msg_zhuce=str_replace("[name]",$name,$msg_zhuce);
				$msg_zhuce=str_replace("[WEBTITLE]",WEBTITLE,$msg_zhuce);
				$msg_zhuce=str_replace("[tg]",$tg,$msg_zhuce);
				$insert = "INSERT into ".$BIAOTOU."msg(ddusername,title,content,addtime,senduser) values ('$name','欢迎注册".WEBTITLE."','".$msg_zhuce."','".$sj."','网站客服')";
				mysql_query($insert);
				
				if (ZHUCESONG != 0) {
					$insert = "INSERT INTO " . $BIAOTOU . "mingxi(ddusername,shijian,je,addtime,memo) values ('" . $name . "','注册赠送','" . ZHUCESONG . "','" . $sj . "','注册赠送金额" . ZHUCESONG . "元')";
					mysql_query("set names utf8");
					mysql_query($insert);
					$msg_zhucesong=str_replace("[ZHUCESONG]",ZHUCESONG,$msg_zhucesong);
					$insert = "INSERT into ".$BIAOTOU."msg(ddusername,title,content,addtime,senduser) values ('$name','注册赠送','".$msg_zhucesong."','$sj','网站客服')";
					mysql_query($insert);
				}
			}
		}
	}
	elseif(UC==0){
	    $sql="select `Id`,`dengji` from ".$BIAOTOU."user where `ddusername`='$name' and `ddpassword`='$md5pwd'";
	    $query=mysql_query($sql);
	    $row=mysql_fetch_array($query);
		$uid=$row[0];
		$dengji=$row[1];
	}
	
	if($uid>0){//是否记录登陆状态
	    $sql="update ".$BIAOTOU."user set ddpassword='".$md5pwd."',loginnum=loginnum+1 ,lastlogintime='".$sj."' where `ddusername`='".$name."'"; //不管是否修改过，都更新密码
		mysql_query($sql);
	    $_SESSION["duoduouser"] = $name; 
		$_SESSION["dduserid"] = $uid;
		$_SESSION["dduserlevel"] = $dengji;
		setcookie("ddusername", $name, time()+1000*24*60*60,"/",SURL);
		setcookie("ddpassword", $md5pwd, time()+1000*24*60*60,"/",SURL);
	}
	return $uid;
}

function taobao_comment(){
    $plurl=$_GET['plurl'];
$s=file_get_contents($plurl);
$s=str_replace('TB.detailRate = ','',$s);
$s=trim(mb_convert_encoding($s,"utf-8","gb2312"));
$web=json_decode($s);
$arr=json_to_array($web);

$pjdf=$arr['scoreInfo']['merchandisScore'];
$pjdfnum=$arr['scoreInfo']['merchandisTotal'];
$pjarr=$arr['rateListInfo']['rateList'];
$pingjianum=$arr['rateListInfo']['paginator']['items'];
//$page=$arr['rateListInfo']['paginator']['pages'];
$totalpj=$arr['rateListInfo']['paginator']['items'];
if($totalpj>100){
	$totalpj=100;
}
$pagesize=20;
echo $totalpj."@".$pjdf."@".$pjdfnum."@".$pingjianum."@"; //页数  分数  打分次数  评价人数
?>
<?php
foreach($pjarr as $row){
?>
<li style="width:740px; line-height:20px; border-bottom:1px solid #ddd;"><div style="float:left; width:580px; margin-left:10px; margin-top:5px; margin-bottom:5px;">
<?=$row->rateContent?><br><font color="#999999">[<?=$row->rateDate?>]</font></div><div style="float:right; width:140px; line-height:20px; margin-top:5px; margin-bottom:5px;">买家：<?=$row->displayUserNick?><?php if($row->displayRatePic!=''){?><br><img src="images/<?=$row->displayRatePic?>" /><?php }?>
</div></li>
<?php } 
}

$fun_arr=array('checkLogin','taobao_comment','cacheSize');
if(in_array($_GET['fun'],$fun_arr)) echo $reval=call_user_func($_GET['fun']);
else echo "what are doing";
mysql_close($cfg_link);
?>